<?php
/**
 * Created by PhpStorm.
 * User: changyifan
 * Date: 2018/3/26
 * Time: 下午6:41
 */

namespace Home\Model;
use Think\Model\BaseModel;

class StudentModel extends BaseModel{

    protected $_link = array(
        'Naturalclass' => array(
            'mapping_type' => self::BELONGS_TO,
            'class_name' => 'Naturalclass',
            'foreign_key' => 'cla_id',
            'mapping_fields' => 'pro_id,stu_gra,cla_name',
            'as_fields' => 'pro_id,stu_gra,cla_name'
        ),
        'Profession' => array(
            'mapping_type' => self::BELONGS_TO,
            'class_name' => 'Profession',
            'foreign_key' => 'pro_id',
            'mapping_fields' => 'dept_id',
            'as_fields' => 'dept_id'
        ),
        'Department' => array(
            'mapping_type' => self::BELONGS_TO,
            'class_name' => 'Department',
            'foreign_key' => 'dept_id',
            'mapping_fields' => 'sch_id',
            'as_fields' => 'sch_id'
        ),
    );



    public function getStudentInfoByClassIdAndStuNum($cla_id,$stu_num){

        if ($cla_id == 0) {
            $con['cla_id'] = array('like', "%%");
        } else {
            $con['cla_id'] = $cla_id;
        }
        $con['stu_id'] = array('like' , "%$stu_num%");
        $stu_info = $this -> where($con) ->relation(true)-> select();

        if ($stu_info) {
            return $stu_info;
        } else {
            return array();
        }
    }
}